local skel = fk.CreateSkill {
  name = "lb__qiusheng",
}

Fk:loadTranslationTable {
  ["lb__qiusheng"] = "求生",
  [":lb__qiusheng"] = "出牌阶段限一次，你可以令一名已受伤的角色回复1点体力，然后指定距离其为1以内的一名其他角色，后者展示手牌并将其中的【杀】依次对回复体力的角色使用。",

  ["#lb__qiusheng"] = "求生：你可以令一名已受伤的角色回复1点体力",

  ["#lb__qiusheng-ask"] = "求生：你可以令一角色展示手牌并对 %dest 使用其中的【杀】",

  ["$lb__qiusheng1"] = "目标标本出现，准备采集。",
  ["$lb__qiusheng2"] = "为了去往远方……",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#lb__qiusheng",
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.phase) == 0
  end,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select:isWounded()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:recover({
      who = target,
      num = 1,
      recoverBy = player,
      skillName = "lb__qiusheng",
    })
    local tos = table.filter(room:getAlivePlayers(), function(p)
      return p:distanceTo(target) == 1 and not p:isKongcheng()
    end)
    if #tos > 0 then
      tos = room:askToChoosePlayers(player, {
        targets = tos,
        min_num = 1,
        max_num = 1,
        skill_name = skel.name,
        prompt = "#lb__qiusheng-ask::" .. target.id,
        cancelable = false
      })
      if #tos > 0 then
        local t = tos[1]
        local cards = t:getCardIds("h")
        room:showCards(cards, t)
        while not target.dead do
          if #cards == 0 then break end
          room:delay(200)
          local card = Fk:getCardById(cards[1])
          if card.trueName == "slash" and table.contains(t:getCardIds("h"), card.id) and
              t:canUseTo(card, target, { bypass_distances = true, bypass_times = true }) then
            room:useCard({
              card = card,
              from = t,
              tos = { target },
              extraUse = true,
            })
          end
          table.remove(cards, 1)
        end
      end
    end
  end,
})

return skel
